define(function(require, exports, module) {
    /**
     * 注册路由
     */
    exports.registerRouteState = function(app, navItems, unCreateParent) {
        var states = {};

        angular.forEach(navItems, function(item) {
            // 处理多级state，自动添加各个父级state
            if (!unCreateParent) {
                var paths = item.state.split(/\./g);
                var currentPath = '';
                angular.forEach(paths, function(path) {
                    currentPath += path;
                    if (!states[currentPath]) {
                        states[currentPath] = item;
                    }

                    currentPath += '.'
                });
            } else {
                states[item.state] = item;
            }

        });

        // 遵循约定优于配置的原则自动批量注册路由
        angular.forEach(states, function(item, state) {
            var path = item.path || state.replace(/\./g, '/');
            var lastState = state.match(/(\w+)$/)[0];
            app.register.registerState(state, {
                url: '/' + lastState,
                templateUrl: seajs.data.baseUrl + '/' + path + '/view/' + lastState + '.html',
                resolve: app.getRouteResolve('../../' + seajs.data.baseUrl + '/' + path + '/mod.js')
            });
        });
    }
});